# Create your views here.
import re
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.contrib.auth import logout
from django.template import RequestContext
from market.marketData import MarketData
from market.authentification import authentificatePlayer, authentificateUser
from market.findNewRepRule2Ter import FindNewRepRule2TerHelper
from market.view import View
from market.mathView import view2vec
from market.models import UserProfile
from market.models import Asset,Player
from market.models import Strategy, AssetPercentageInStrategy, Fund
from market.mathView import indexOfAssetInList
from market.models import WebSiteComment
from market.jsonsForCharts import getComments
from market.controllerAdminView import getBetroomFromUser

from market.exceptionHandler import handleRequestUserPOSTWithException

from django.contrib.auth.tokens import default_token_generator
from django.contrib.sites.models import Site
from django.template import loader
from django.template.context import Context
from django.utils.http import int_to_base36



from market.cometHelper import getMarketPlacePlayerStatus
from market.cometHelper import getChatRoomPlayerStatus

from django.utils import simplejson



################################################################################################################
# web to select a betroom. This is not necessary linked to the creation but it was as bad too create a controller just for thsi function
def betroomsView(request):

        alternative_response_list = [] #the answer to return if the player could not be authentificated with a dummy initialisation
        if not( authentificateUser( request, alternative_response_list ) ):
                return alternative_response_list[0]

        return render_to_response('home/betrooms.html',
                        {'userName':request.user.username },
                        context_instance=RequestContext(request) )


###########################################################################################
# this controller is the one calling the view for the help
def helpView(request):

	alternative_response_list = [] #the answer to return if the player could not be authentificated with a dummy initialisation
        if not( authentificateUser( request, alternative_response_list ) ):
                return alternative_response_list[0]
        
	return render_to_response(
                'home/help.html',
                {'userName':request.user.username },
                context_instance=RequestContext(request) )

###########################################################################################
# this controller is the one calling the view for the help
def settingsView(request):

	alternative_response_list = [] #the answer to return if the player could not be authentificated with a dummy initialisation
        if not( authentificateUser( request, alternative_response_list ) ):
                return alternative_response_list[0]
	return render_to_response(
                'home/settings.html',
                {
                        'userName':request.user.username,
                        'user_email': request.user.email,
                        'reset_psw_msg':'',
                        'reset_email_msg': '',
                        'send_me_email': request.user.get_profile().sendMeEmails
                },
                context_instance=RequestContext(request) )

###########################################################################################
# return the page with the rules and the explanation
def celibaxRules(request):
        pdf = open( 'Doc/celibax.pdf', "rb").read()
        return HttpResponse(pdf, mimetype='application/pdf')





        
